package net.qunzhi.modules.historyspider.client;

import net.qunzhi.modules.historyspider.utils.HTTPUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.util.EntityUtils;

public class URLHandle {

    public static void urlParser(HttpClient client, String url, Integer equipmentId, String maxtime, String pressureOrFlow) throws Exception {

      try {
          //获取响应资源
          HttpResponse response = HTTPUtils.getHtml(client, url);
          //System.out.println(response.getStatusLine()+"------");

            //获取响应状态码
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == 200) {
                //页面编码
                String entity = EntityUtils.toString(response.getEntity(), "gbk");
                xiParse.getData(entity, equipmentId, maxtime, pressureOrFlow);
            } else {
                EntityUtils.consume(response.getEntity());//释放资源实体
            }
        } catch (Exception e){
          throw new Exception("网络异常");
      }

    }
}
